package com.aw.guiguzi.module.manager.msg.adapter

import android.widget.LinearLayout
import com.aw.baselib.util.AwDataUtil
import com.aw.guiguzi.R
import com.aw.guiguzi.bean.MsgItemBean
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

class ManagerMsgListAdapter :
    BaseQuickAdapter<MsgItemBean, BaseViewHolder>(R.layout.adapter_manager_msg_list) {
    private var mList: MutableList<MsgItemBean>? = ArrayList()

    init {
        if (mList == null) {
            mList = ArrayList()
        }
    }

    override fun convert(helper: BaseViewHolder, bean: MsgItemBean) {
        helper.setText(R.id.tv_userId, bean.userId)
            .setText(R.id.tv_content, bean.templateContent)
            .setText(
                R.id.tv_createTime,
                if (AwDataUtil.isEmpty(bean.createTime)) "--" else bean.createTime
            )
            .setText(R.id.tv_readStatus, if (bean.isReadStatus) "已读" else "未读")
            .setTextColor(
                R.id.tv_readStatus,
                if (bean.isReadStatus) mContext.resources.getColor(com.aw.baselib.R.color.black) else mContext.resources.getColor(
                    com.aw.baselib.R.color.red
                )
            )
        val ll_layout = helper.getView<LinearLayout>(R.id.ll_layout)
        if (helper.layoutPosition % 2 == 0) {
            ll_layout.setBackgroundColor(mContext.resources.getColor(com.aw.baselib.R.color.color_item_1))
        } else {
            ll_layout.setBackgroundColor(mContext.resources.getColor(com.aw.baselib.R.color.color_item_2))
        }
    }

    fun addAllData(dataList: MutableList<MsgItemBean>?) {
        mList = dataList
        setNewData(mList)
        notifyDataSetChanged()
    }

    fun clearData() {
        if (mList != null) {
            val startPosition = 0 //hasHeader is 1
            val preSize = mList!!.size
            if (preSize > 0) {
                mList!!.clear()
                notifyItemRangeRemoved(startPosition, preSize)
            }
        }
    }
}